package zb.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zb.blog.base.bean.Result;
import zb.blog.base.global.GlobalVar;
import zb.blog.bean.PrivateAccountBean;
import zb.blog.dao.PrivateAccountDao;
import zb.blog.service.PrivateAccountService;

import java.util.List;
import java.util.Map;

@Service
public class PrivateAccountServiceImpl implements PrivateAccountService {
    @Autowired
    private PrivateAccountDao privateAccountDao;

    @Override
    public PageInfo<PrivateAccountBean> list(Map<String, String> param) {
        PageHelper.startPage(Integer.valueOf(param.get("pageNum")), Integer.valueOf(param.get("pageSize")));
        List<PrivateAccountBean> list = privateAccountDao.list(param);
        PageInfo<PrivateAccountBean> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Result add(PrivateAccountBean privateAccountBean) {
        Result r = new Result();
        privateAccountDao.add(privateAccountBean);
        r.setSuccess(GlobalVar.SUCCESS);
        return r;
    }

    @Override
    public Result deleteById(Integer id) {
        Result r = new Result();
        privateAccountDao.deleteById(id);
        r.setSuccess(GlobalVar.SUCCESS);
        r.setMsg("删除成功");
        return r;

    }

    @Override
    public Result updateById(PrivateAccountBean privateAccountBean) {
        Result r = new Result();
        r.setSuccess(GlobalVar.SUCCESS);
        r.setMsg("更新成功！");
        privateAccountDao.updateById(privateAccountBean);
        return r;
    }

    @Override
    public PrivateAccountBean getById(Integer id) {
        return privateAccountDao.getById(id);
    }
}
